<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ include file="/taglibs.jsp"%>
<html>
<head>
<title>IT管理后台</title>
<link rel="stylesheet" type="text/css" href="/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="/js/themes/icon.css">
<script type="text/javascript" src="/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="/js/easyui_validatebox.js"></script>
<script type="text/javascript" src="/js/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="/js/util.js"></script>
<script src="/js/print.js" type="text/javascript"></script>
<style type="text/css">
td {
	font-size: 13px
}
table.ttb{border-left:solid 1px #99bbe8;border-top: solid 1px #99bbe8;}
table.ttb td{word-break: break-all; word-wrap:break-word;vertical-align: top; padding-left:8px; border-right: solid 1px #99bbe8;border-bottom: solid 1px #99bbe8; line-height: 24px; font-size: 12px;}
.bg001{font-weight: bold; color: #333; background-color: #edf4fc}
</style>
	<script>
		$(function(){
			$('#tab').datagrid({
				title:'使用记录',
				iconCls:'icon-save',
				nowrap: false,
				striped: true,
				pageSize:20,
				sortName:"id",
				sortOrder:"desc",
				pageList:[10,20,30,40,50],
				url:'/itmanager/kcjl/json',
				remoteSort: false,
				idField:'id',
				frozenColumns:[[
	                	{field:'ck',checkbox:true},
	                	{title:'记录时间',field:"jlsj",width:80},
						{title:'部门',field:"bm",width:80},
						{title:'员工编号',field:"ygbh",width:80},
						{title:'姓名',field:"xm",width:80},
						{title:'使用物品',field:"sywp",width:120},
						{title:'使用数量',field:"sl",width:80},
						{title:'使用类型',field:"sylx",width:120,formatter:
					    	 function(value,rowData,rowIndex){
								if(value=="0"){
									return "<font color='red'>个人使用</font>";
								}else if(value=="1"){
									return "<font color='red'>他人使用(<font color='blue'>"+rowData.trxm+"</font>)</font>";
								}else if(value=="2"){
									return "<font color='red'>部门使用</font>";
								}
							}
						}
	                ]],
				columns:[
					[
						{title:"备注",field:"bz",width:80}
					]
				],
				fit:true,
				fitColumns:true,
				border:false,
				pagination:true,
				rownumbers:true,
				toolbar:[{
					id:'1',
					text:'添加',
					disabled:true,
					iconCls:'icon-add',
					handler:function(){
						kcjladd.window({
							onBeforeOpen:function(){
								kcjladdform.form('clear');
								$("#jlsj-add").datebox("setValue",textDate());
								$("#sylx-add").val("0");
								$.ajax({
									   type: "get",
									   url: "/itmanager/common/cllx",
									   data: "lx=bm",
									   success: function(msg){
										   var bmm = $("#bm-add")[0];  //把jquery对象转成dom对象使用
										   clearSel(bmm); //清空
										   var value1="";
										   var text1="-请选择部门-(可不选)";
										   var option1=new Option(text1,value1);
										   bmm.options.add(option1);
										   msg=$.parseJSON(msg);
										   $.each(msg, function(i, b) {
												var value = b.id;
												var text = b.clmc;
												var option = new Option(text, value);
												bmm.options.add(option);
											});
									   }
									});
								$.ajax({
									   type: "get",
									   url: "/itmanager/kctj/list",
									   success: function(msg){
										   var zww = $("#sywpid-add")[0];  //把jquery对象转成dom对象使用
										   clearSel(zww); //清空
										   var value1="";
										   var text1="-请选择物品-";
										   var option1=new Option(text1,value1);
										   zww.options.add(option1);
										   msg=$.parseJSON(msg);
										   $.each(msg, function(i, b) {
												var value = b.id;
												var text = "["+b.jhsj+"]"+b.wpmc+"("+b.wpsl+")";
												var option = new Option(text, value);
												zww.options.add(option);
											});
									   }
									});
							}
						});
						kcjladd.window("open");
					}
				},'-',{
					id:'2',
					text:'修改',
					disabled:true,
					iconCls:'icon-edit',
					handler:function(){
						kcjledit.window({
							onBeforeOpen:function(){
								kcjleditform.form('clear');
								var rows = $("#tab").datagrid("getSelections");
								var length = rows.length;
								if(length != 1){
									$.messager.alert("友情提示","<br/><b>只能选择一条记录！</b>","error");
									return false;
								}
								var id=rows[0].id;
								$.ajax({
									   type: "get",
									   url: "/itmanager/common/cllx",
									   data: "lx=bm",
									   success: function(msg){
										   var bmm = $("#bmid-edit")[0];  //把jquery对象转成dom对象使用
										   clearSel(bmm); //清空
										   var value1="";
										   var text1="-请选择部门-(可不选)";
										   var option1=new Option(text1,value1);
										   bmm.options.add(option1);
										   msg=$.parseJSON(msg);
										   $.each(msg, function(i, b) {
												var value = b.id;
												var text = b.clmc;
												var option = new Option(text, value);
												bmm.options.add(option);
											});
									   }
									});
								$.ajax({
							 		type:"get",
							 		url:"/itmanager/kcjl/show",
							 		data:"id="+id,
							 		cache:false,
							 		success:function(data){
							 		 	data=$.parseJSON(data);
										$("#jlsj-edit").datebox("setValue",data.jlsj);
										$("#bmid-edit").val(data.bmid);
										$("#ygbh-edit").val(data.ygbh);
										$("#xm-edit").val(data.xm);
										$("#sylx-edit").val(data.sylx);
										if(data.sylx=="1"){
											$("#hidden-xm-edit").show();
										}else{
											$("#hidden-xm-edit").hide();
										}
										$("#trxm-edit").val(data.trxm);
										$("#bz-edit").val(data.bz);
							 		}
							 	});
							}
						});
						kcjledit.window("open");
					}
				},'-',{
					id:'3',
					text:'删除',
					disabled:true,
					iconCls:'icon-remove',
					handler:function(){
						deleteKcjl();
					}
				},'-',{
					id:'9',
					text:'打印',
					disabled:true,
					iconCls:'icon-print',
					handler:function(){
						startPrint($(".datagrid-view")[0]);
					}
				}]
			});
			
			 $("#tab").datagrid("getPager").pagination({
				   onSelectPage:function(){
					  $("#tab").datagrid("clearSelections");
					  var queryParams = $.extend({},$("#tab").datagrid("options").queryParams,
							  {spxm:$("#xm-search").val(),spsywpid:$("#sywpid-search").val(),spbm:$("#bm-search").val(),spbfjlsj:$("#bfjlsj-search").val(),spafjlsj:$("#afjlsj-search").val()}); 
					  $("#tab").datagrid("reload",queryParams);
				   }
			  });
			 
			kcjl = $('#kcjl-window').window({
				modal: true,
				maximizable:false,
				minimizable:false,
				collapsible:false,
				closed:true
			});
			kcjladd = $('#kcjl-add').window({
				modal: true,
				maximizable:false,
				minimizable:false,
				collapsible:false,
				closed:true
			});
			kcjladdform=kcjladd.find("form");
			kcjledit = $('#kcjl-edit').window({
				modal: true,
				maximizable:false,
				minimizable:false,
				collapsible:false,
				closed:true
			});
			kcjledit.window({
				onBeforeClose:function(){
					var queryParams = $.extend({},$("#tab").datagrid("options").queryParams);
		 			$("#tab").datagrid("reload",queryParams);
				}
			});
			kcjleditform=kcjledit.find("form");
			
			 var ens='${param.en}';
			 var en=ens.split(":");
			 for(var i=0;i<en.length;i++){
				 if(en[i] != "" && en[i] != null){
				 	$("#"+en[i]).linkbutton('enable');
				 }
			 }
			
		});
		
		var find = function(){
			$("#tab").datagrid("clearSelections");
			var queryParams = $.extend({},$("#tab").datagrid("options").queryParams,
					{spxm:$("#xm-search").val(),spsywpid:$("#sywpid-search").val(),spbm:$("#bm-search").val(),spbfjlsj:$("#bfjlsj-search").datebox("getValue"),spafjlsj:$("#afjlsj-search").datebox("getValue")}); 
			$("#tab").datagrid("getPager").pagination({pageNumber:1});
			$("#tab").datagrid("reload",queryParams);
		}
		
		
		function mtext(target,text){
			$(target).html("&nbsp;");
			$(target).html(text);
		}
		
		function clearSel(oSelect) {
			while (oSelect.childNodes.length > 0) {
				oSelect.removeChild(oSelect.childNodes[0]);
			}

		}
		
		function closeKcjladd(){
			kcjladd.window('close');
		}
		function closeKcjledit(){
			kcjledit.window('close');
		}
		
		function createKcjl(){
			kcjladdform.form('submit', {  
				  url:kcjladdform.action,
				  onSubmit:function(){
				        return $(this).form('validate');
				    },
				  success:function(data){
				          if (data=='success'){  
				        	  	$.messager.alert('信息提示','添加成功！','right');  
				                kcjladd.window('close');  
				                var queryParams = $.extend({},$("#tab").datagrid("options").queryParams);
					 			$("#tab").datagrid("reload",queryParams);
				            } else if(data=='error'){
				            	$.messager.alert('信息提示','添加失败！','error');
				            }
				     }  
			});  
		}
		
		function editKcjl(){
			var rows = $("#tab").datagrid("getSelections");
			var length = rows.length;
			if(length != 1){
				$.messager.alert("友情提示","<br/><b>只能选择一条记录！</b>","error");
				return false;
			}
			var id=rows[0].id;
			kcjleditform.form('submit', {  
				  url:"/itmanager/kcjl/edit?id="+id,
				  onSubmit:function(){
				        return $(this).form('validate');
				    },
				  success:function(data){
				          if (data=='success'){  
				        	  	$.messager.alert('信息提示','修改成功！','right');  
				                
				            } else if(data=='error'){
				            	$.messager.alert('信息提示','修改失败！','error');
				            }
				     }  
			});  
		}
		
		function showtrxm(value){
			if(value=="1"){
				$("#hidden-xm").show();
			}else{
				$("#hidden-xm").hide();
			}
		}
		
		function showedittrxm(value){
			if(value=="1"){
				$("#hidden-xm-edit").show();
			}else{
				$("#hidden-xm-edit").hide();
			}
		}
		
		function getlimitnumber(value){
			$.ajax({
				type:"post",
				url:"/itmanager/kctj/show",
				data:"id="+value,
				cache:false,
				success:function(msg){
					msg=$.parseJSON(msg);
					$("#sl-add").numberbox({
						max:msg.wpsl,
						min:0
					});
				}
			});
		}
		
		var deleteKcjl = function(){
			var rows = $("#tab").datagrid("getSelections");
			var length = rows.length;
			if(length == 0){
				$.messager.alert("友情提示","<br/><b>请先选择记录！</b>","error");
				return false;
			}
			var ids = [];
			for(var i=0;i<length;i++){
				ids.push(rows[i].id);
			}
			ids.join(",");
			$.messager.confirm("友情提示","<br/><b>确定删除记录？</b>",function(result){
				if(result){
					$.ajax({
				 		type:"post",
				 		url:"/itmanager/kcjl/delete",
				 		data:"ids="+ids,
				 		success:function(data){
				 			if(data=='success'){
				 		 		var queryParams = $.extend({},$("#tab").datagrid("options").queryParams);
				 				$("#tab").datagrid("reload",queryParams);
				 				$("#tab").datagrid("clearSelections");
				 			}else if(data=='error'){
				 				$.messager.alert("友情提示","<br/><b>删除记录出错！</b>","error");
				 			}
				 		}
				 	});
				}
			});
		};
		
		
	</script>
</head>
<body class="easyui-layout">
	<div region="north" border="false" style="height:80px;" iconCls="icon-search" title="查询条件">
		<table width="100%" height="100%" style="background-color:#E0ECFF ">
			<thead>
				<tr>
					<td align="center">姓名：</td>
					<td><input type="text" name="spxm" id="xm-search" value="${smap.spxm }"></td>
					<td align="center">使用物品：</td>
					<td>
						<select name="spsywpid" id="sywpid-search">
							<option value="">--请选择物品--</option>
							<c:forEach items="${wp }" var="b">
								<option value="${b.id }" <c:if test="${smap.spsywpid==b.id }">selected</c:if>>${b.wpmc }</option>
							</c:forEach>
						</select>
					</td>
					<td align="center">查询时间：</td>
					<td nowrap="nowrap">
						<input name="spbfjlsj" id="bfjlsj-search" class="easyui-datebox"/>到<input name="spafjlsj" id="afjlsj-search" class="easyui-datebox"/>
					</td>
					<td><a id="4" disabled="true" class="easyui-linkbutton" iconCls="icon-search" onclick="find()">查询</a></td>
				</tr>
			</thead>
		</table>
	</div>
	<div id="center" region="center">
		<table id="tab"></table>
	</div>
	
	
	
	<div id="kcjl-add" title="添加记录" style="width:350px;height:380px;">
				<div style="text-align: center;padding-top: 5px;">
					<form method="post" action="/itmanager/kcjl/add">
						<table>
							<tr>
								<td>记录时间：</td>
								<td><input name="jlsj" id="jlsj-add" type="text" class="easyui-datebox" required="true" style="width:150px;"></input></td>
							</tr>
							<tr>
								<td>部门：</td>
								<td>
									<select name="bmid" id="bm-add" style="width:150px;"></select>
									
								</td>
							</tr>
							<tr>
								<td>员工编号：</td>
								<td><input name="ygbh" id="ygbh-add" type="text"></input></td>
							</tr>
							<tr>
								<td>姓名：</td>
								<td><input name="xm" id="xm-add" type="text" class="easyui-validatebox" required="true"></input></td>
							</tr>
							<tr>
								<td>使用物品：</td>
								<td><select name="sywpid" id="sywpid-add" style="width:150px;" class="easyui-validatebox" required="true" onchange="getlimitnumber(this.value)"></select></td>
							</tr>
							<tr>
								<td>使用数量：</td>
								<td><input name="sl" id="sl-add" type="text" class="easyui-numberbox" required="true"></input></td>
							</tr>
							<tr>
								<td>使用类型：</td>
								<td>
									<select name="sylx" id="sylx-add" style="width:150px" onchange="showtrxm(this.value)">
										<option value="0">个人使用</option>
										<option value="1">他人使用</option>
										<option value="2">部门使用</option>
									</select>
								</td>
							</tr>
							
							<tr id="hidden-xm" style="display: none;">
								<td>他人姓名：</td>
								<td><input name="trxm" id="trxm-add" type="text"></input></td>
							</tr>
							<tr>
								<td>备注：</td>
								<td><textarea name="bz" id="bz-add" style="width:150px;"></textarea></td>
							</tr>
						</table>
					</form>
				</div>
				<div style="text-align:center;">
					<a href="javascript:void(0)" onclick="createKcjl()" class="easyui-linkbutton" id="kcjl-add-button" icon="icon-save">添加</a>
					<a href="javascript:void(0)" onclick="closeKcjladd()" class="easyui-linkbutton" id="kcjl-cancel-button" icon="icon-cancel">取消</a>
				</div>
		</div>
		
		<div id="kcjl-edit" title="修改记录信息" style="width:350px;height:380px;">
				<div style="text-align: center;padding-top: 5px;">
					<form method="post" action="/itmanager/kcjl/edit">
						<table>
							<tr>
								<td>记录时间：</td>
								<td><input name="jlsj" id="jlsj-edit" type="text" class="easyui-datebox" required="true" style="width:150px;"></input></td>
							</tr>
							<tr>
								<td>部门：</td>
								<td>
									<select name="bmid" id="bmid-edit" style="width:150px;"></select>
									
								</td>
							</tr>
							<tr>
								<td>员工编号：</td>
								<td><input name="ygbh" id="ygbh-edit" type="text"></input></td>
							</tr>
							<tr>
								<td>姓名：</td>
								<td><input name="xm" id="xm-edit" type="text" class="easyui-validatebox" required="true"></input></td>
							</tr>
							
							<tr>
								<td>使用类型：</td>
								<td>
									<select name="sylx" id="sylx-edit" style="width:150px" onchange="showedittrxm(this.value)">
										<option value="0">个人使用</option>
										<option value="1">他人使用</option>
										<option value="2">部门使用</option>
									</select>
								</td>
							</tr>
							
							<tr id="hidden-xm-edit" style="display: none;">
								<td>他人姓名：</td>
								<td><input name="trxm" id="trxm-edit" type="text"></input></td>
							</tr>
							<tr>
								<td>备注：</td>
								<td><textarea name="bz" id="bz-edit" style="width:150px;"></textarea></td>
							</tr>
						</table>
					</form>
				</div>
				<div style="text-align:center;">
					<a href="javascript:void(0)" onclick="editKcjl()" class="easyui-linkbutton" id="kcjl-edit-button" icon="icon-ok">修改</a>
					<a href="javascript:void(0)" onclick="closeKcjledit()" class="easyui-linkbutton" id="kcjl-cancel-button" icon="icon-cancel">取消</a>
				</div>
		</div>

</body>
</html>